package com.car.loan.project.xr.util.repayment.impl;

import com.car.loan.project.xr.util.repayment.FinancingAmountInterface;
import java.math.BigDecimal;
import java.math.MathContext;
import org.springframework.stereotype.Service;

/**
 * 分期金额*（1+银行基础费率）/（1+执行费率） 个位 向上
 *
 * @author huangding
 * @date 2020/3/21 20:08
 */
@Service("financingAmountB1")
public class FinancingAmountB1 implements FinancingAmountInterface {

    @Override
    public Integer getFinancingAmount(BigDecimal installmentAmount, BigDecimal rate,
        BigDecimal bankRate) {
        BigDecimal add1 = rate.divide(new BigDecimal(100), MathContext.DECIMAL128)
            .add(BigDecimal.ONE);
        BigDecimal add2 = bankRate.divide(new BigDecimal(100), MathContext.DECIMAL128)
            .add(BigDecimal.ONE);
        BigDecimal divide = installmentAmount.multiply(add2).divide(add1, MathContext.DECIMAL128);
        return divide
            .setScale(2, BigDecimal.ROUND_HALF_UP)
            .setScale(0, BigDecimal.ROUND_CEILING).intValue();
    }
}
